package map;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class mapDemo2 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("语文", 99);
        map.put("数学", 49);
        map.put("英语", 97);
        map.put("化学", 98);
        map.put("物理", 69);
        System.out.println(map);

        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println("key:" + key);
        }
//        keySet.forEach(e -> System.out.println(e)); //forEach
//        keySet.forEach(System.out::println);

        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        for (Map.Entry<String, Integer> e : entrySet) {
            String key = e.getKey();
            Integer value = e.getValue();
            System.out.println(key + ":" + value);
        }

//        map.forEach(new BiConsumer<String, Integer>() {
//            @Override
//            public void accept(String s, Integer i) {
//                System.out.println(s+":"+i); //s-k,i-y
//            }
//        });
//        ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
        map.forEach((k,v)-> System.out.println(k+":"+v));



        Collection<Integer> values = map.values();
        for (Integer value : values) {
            System.out.println("value:" + value);
        }

//        keySet.forEach(new Consumer<String>() {
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });
//        ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
        keySet.forEach(s -> System.out.println(s));
//        ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
        keySet.forEach(System.out::println);



    }
}
